<template>

  <el-dialog
    title="选择分类"
    :visible.sync="movingGoodsTyep"
    width="304px"
    :close-on-click-modal="false">
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item label="商品分类">
        <div class="block">
          <el-cascader
            v-model="productCategoryId"
            :options="options"
            :props="props"
            clearable></el-cascader>
        </div>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="movingGoodsTyep = false">取 消</el-button>
    <el-button type="primary" @click="saveClick">确 定</el-button>
  </span>
  </el-dialog>
</template>

<script>
  import { list as productCategoryList } from '@/api/productCategory'
  import {BatchUpdate} from '@/api/product'
    export default {
        data(){
          return{
            movingGoodsTyep:false,
            options: [],
            productCategoryId:'',
            props:{
              value:'id',
              label:'name',
              children:'childrens',
              checkStrictly:true
            }
          }
        },
      props:[
        'procudtDate'
      ],
      created(){
        this.loadProductCategory()
      },
      methods: {
        show(){
          this.movingGoodsTyep = true
          this.loadProductCategory()
        }  ,
        handleClose(done) {
          this.$confirm('确认关闭？')
            .then(_ => {
              done();
            })
            .catch(_ => {});
        },
        loadProductCategory() {
          productCategoryList().then(response => {
            this.options = response.data
          }).catch(error => {
          })
        },
        saveClick(){
          var _this = this
          this.$confirm('是否继续移动?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            // this.$message({
            //   type: 'success',
            //   message: '将移动'+JSON.stringify(this.procudtDate)+'到'+this.productCategoryId
            // });
            _this.updataClick()
          }).catch(() => {

          });
        },
        updataClick(){
          var _this = this
          var productForm = []
          console.log('1111')
          this.procudtDate.forEach(function (item) {
             var product = {
               id : item,
               productCategoryId:_this.productCategoryId[_this.productCategoryId.length-1]
             }
             productForm.push(product)
          })
          console.log('1111')
          BatchUpdate(productForm).then(response => {
            console.log(response)
            this.$message({
              type: 'success',
              message: response.content
            });
            _this.movingGoodsTyep = false
            _this.$emit('productListClick')
          }).catch(error => {
          })
        }
      }
    }
</script>

<style scoped>
  /deep/.el-form-item{
    margin-right: 0;
    margin-bottom: 0;
  }
</style>
